/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dailynewsreader.view;

import dailynewsreader.model.LabelStorage;
import javax.swing.JOptionPane;

/**
 * Refactoring: Commentek!!!
 * @author PM
 */
public class RSSRenameFrame extends javax.swing.JFrame {

    /**
     * Az rss olvasó panel
     */
    private RSSReaderPanel rssPanel;
    
    private String feedTitle;
    
    /**
     * A feliratkozó ablak konstruktora
     * @param rssPanel Rss olvasó panel
     */
    public RSSRenameFrame(RSSReaderPanel rssPanel) {
        initComponents();
        this.rssPanel = rssPanel;
    }
    
    public void setName(String name){
        feedTitle = name;
        rssFeedRenameText.setText(name);
    }
    
    /**
     * Átnevezés
     * @param text
     * @throws Exception 
     */
    private void rename(String text) throws Exception {
        if (rssPanel.renameFeed(feedTitle, text)){
            this.dispose();
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        rssFeedRenameButton = new javax.swing.JButton();
        rssFeedRenameText = new javax.swing.JTextField();
        rssFeedRenameLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(LabelStorage.SUBSCRIPTION_FRAME_TITLE);
        setResizable(false);

        rssFeedRenameButton.setText(LabelStorage.RENAME_FRAME_BUTTON_TEXT);
        rssFeedRenameButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rssFeedRenameButtonActionPerformed(evt);
            }
        });

        rssFeedRenameLabel.setText(LabelStorage.RENAME_FRAME_LABEL);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(rssFeedRenameLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rssFeedRenameText, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(rssFeedRenameButton))
                .addContainerGap(82, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rssFeedRenameLabel)
                    .addComponent(rssFeedRenameText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(rssFeedRenameButton)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Feliratkozás gombra kattintás kezelése
     * @param evt 
     */
    private void rssFeedRenameButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rssFeedRenameButtonActionPerformed
        try {
            this.rename(rssFeedRenameText.getText());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, LabelStorage.ERROR_DESCRIPTION + ex.getMessage(), LabelStorage.ERROR_TITLE, JOptionPane.ERROR_MESSAGE);            
        }
    }//GEN-LAST:event_rssFeedRenameButtonActionPerformed

   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton rssFeedRenameButton;
    private javax.swing.JLabel rssFeedRenameLabel;
    private javax.swing.JTextField rssFeedRenameText;
    // End of variables declaration//GEN-END:variables

}
